package com.jn.erp.wechat.student.api.controller;

import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.common.utils.DateUtils;
import com.jn.erp.security.utils.SecurityUtils;
import com.jn.erp.wechat.common.api.controller.base.BaseWxAuthController;
import com.jn.erp.wechat.common.api.entity.dto.WxUserDto;
import com.jn.erp.wechat.core.WxMessageData;
import com.jn.erp.wechat.core.WxTableDataInfo;
import com.jn.erp.wechat.mp.handler.MpMessageHandler;
import com.jn.erp.wechat.student.api.entity.vo.ClassInfoVo;
import com.jn.erp.wechat.student.api.service.ClassInfoService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <pre>
 *  课程课表相关
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/11/5 9:03
 */
@AllArgsConstructor
@RestController
@RequestMapping("/wxs/class")
public class WxsStudentClassController extends BaseWxAuthController {

    @Autowired
    private ClassInfoService classInfoService;
    @Autowired
    private MpMessageHandler mpMessageHandler;

    //-------------------------------------点名情况---------------------
    /**
     * 点名情况日期  (小程序新建)
     * */
    @GetMapping("/orderDateList")
    public AjaxResult orderDateList(ClassInfoVo classInfoVo) {
        //获取登录家长端相关信息
        WxUserDto studentUser = getStudentUser();
        classInfoVo.setUserId(studentUser.getUserId());
        List<ClassInfoVo> list = classInfoService.orderDateList(classInfoVo);
        Map<String, List<ClassInfoVo>> collect = list.stream().collect(Collectors.groupingBy(ClassInfoVo::getClassDate));
        Map<String, String> dateMap = collect.keySet().stream().collect(Collectors.toMap(s -> s.replaceAll("-0", "-"), s -> "deep-spot"));
        return success(dateMap);
    }


    /**
     * 指定日期点名情况列表    /tCourseOrder/orderList
     * */
    @GetMapping("/orderList")
    public WxTableDataInfo orderList(ClassInfoVo classInfoVo) {
        //获取登录家长端相关信息
        WxUserDto studentUser = getStudentUser();
        classInfoVo.setUserId(studentUser.getUserId());
        startPage();
        List<ClassInfoVo> list = classInfoService.orderDateList(classInfoVo);
        return getWxDataTable(list);
    }





}
